#include <iostream>
#include <memory>

// 以请中介代理租房为场景，给出代理模式的demo代码。
class RentHouse
{
public:
    virtual void rent() = 0;
};

class Landlord : public RentHouse
{
public:
    void rent()
    {
        std::cout << "出租这间房屋" << std::endl;
    }
};

class Agent : public RentHouse
{
public:
    Agent(Landlord* rentHouse): _rentHouse(rentHouse) {}

    void rent()
    {
        std::cout << "发布租房信息" << std::endl;
        std::cout << "带租客看房" << std::endl;
        _rentHouse->rent();
        std::cout << "签订合同" << std::endl;
    }
private:
    Landlord* _rentHouse;
};



void test()
{
    std::unique_ptr<Landlord> landlord(new Landlord);
    std::unique_ptr<Agent> agent = std::make_unique<Agent>(landlord.get());
    agent->rent();
}

int main()
{
    test();
    return 0;
}